package com.ruoyi.deeplearn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deeplearn.domain.DeepDatasetFile;
import com.ruoyi.deeplearn.service.IDeepDatasetFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据集文件Controller
 *
 * @author 任伟伟
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/deeplearn/file")
public class DeepDatasetFileController extends BaseController
{
    @Autowired
    private IDeepDatasetFileService deepDatasetFileService;

    /**
     * 查询数据集文件列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepDatasetFile deepDatasetFile)
    {
        startPage();
        List<DeepDatasetFile> list = deepDatasetFileService.selectDeepDatasetFileList(deepDatasetFile);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('deeplearn:file:list')")
    @GetMapping("/list/unmark/{datasetId}")
    public TableDataInfo listUnmark(@PathVariable("datasetId")Long datasetId,
            DeepDatasetFile deepDatasetFile)
    {
        startPage();
        deepDatasetFile.setDatasetId(datasetId);
        deepDatasetFile.setMarkStatus(0);
        List<DeepDatasetFile> list = deepDatasetFileService.selectDeepDatasetFileList(deepDatasetFile);
        return getDataTable(list);
    }

    /**
     * 导出数据集文件列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:file:export')")
    @Log(title = "数据集文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepDatasetFile deepDatasetFile)
    {
        List<DeepDatasetFile> list = deepDatasetFileService.selectDeepDatasetFileList(deepDatasetFile);
        ExcelUtil<DeepDatasetFile> util = new ExcelUtil<DeepDatasetFile>(DeepDatasetFile.class);
        util.exportExcel(response, list, "数据集文件数据");
    }

    /**
     * 获取数据集文件详细信息
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(deepDatasetFileService.selectDeepDatasetFileByFileId(fileId));
    }

    /**
     * 新增数据集文件
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:file:add')")
    @Log(title = "数据集文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepDatasetFile deepDatasetFile)
    {
        return toAjax(deepDatasetFileService.insertDeepDatasetFile(deepDatasetFile));
    }

    /**
     * 修改数据集文件
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:file:edit')")
    @Log(title = "数据集文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepDatasetFile deepDatasetFile)
    {
        return toAjax(deepDatasetFileService.updateDeepDatasetFile(deepDatasetFile));
    }

    /**
     * 删除数据集文件
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:file:remove')")
    @Log(title = "数据集文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(deepDatasetFileService.deleteDeepDatasetFileByFileIds(fileIds));
    }
}
